//
//  TZLuckViewController.m
//  wangYiCaiPiao
//
//  Created by mac on 16/1/6.
//  Copyright © 2016年 tz. All rights reserved.
//

#import "TZLuckViewController.h"
#import "TZBirthdayViewController.h"
#import "TZDrawViewController.h"
#import "TZNumberViewController.h"
#import "TZDreamViewController.h"

@interface TZLuckViewController ()
@property (nonatomic, strong) UIImageView *backImage;
@property (nonatomic, strong) UIImageView *marquee;
@end

@implementation TZLuckViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"幸运选号";
    [self setupUI];
}

//生日选号仪
- (void)birthdayButtonDidClick {
    TZBirthdayViewController *birthdayViewController = [[TZBirthdayViewController alloc] init];
    [self.navigationController pushViewController:birthdayViewController animated:YES];
}

//无敌上上签
- (void)drawButtonDidClick {
    TZDrawViewController *drawViewController = [[TZDrawViewController alloc] init];
    self.navigationController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] init];
    [self.navigationController pushViewController:drawViewController animated:YES];
}

//幸运数字选号仪
- (void)numberButtonDidClick {
    TZNumberViewController *numberViewController = [[TZNumberViewController alloc] init];
    [self.navigationController pushViewController:numberViewController animated:YES];
}

//幸运大转盘
- (void)dreamButtonDidClick {
    TZDreamViewController *dreamViewController = [[TZDreamViewController alloc] init];
    [self.navigationController pushViewController:dreamViewController animated:YES];
}

//更新UI
- (void)setupUI {
    [self addBackImageInController];
    [self addPaoMaDengInController];
    [self addButtonIncontroller];
}

//设置背景
- (void)addBackImageInController {
    self.backImage = [[UIImageView alloc] init];
    [self.view addSubview:self.backImage];
    [self.backImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    self.backImage.image = [UIImage imageNamed:@"luck_entry_background"];
}

//设置跑马灯
- (void)addPaoMaDengInController {
    self.marquee = [[UIImageView alloc] init];
    [self.view addSubview:self.marquee];
    [self.marquee mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(41);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(231);
        make.height.mas_equalTo(29);
    }];
    //设置播放的图片
    self.marquee.animationImages = @[[UIImage imageNamed:@"lucky_entry_light0"],[UIImage imageNamed:@"lucky_entry_light1"]];
    //切换图片事件
    self.marquee.animationDuration = 1;
    //开始动画
    [self.marquee startAnimating];
}

//设置点击按钮
- (void)addButtonIncontroller {
    //生日选号仪
    UIButton *birthdayButton = [[UIButton alloc] init];
    [self.view addSubview:birthdayButton];
    [birthdayButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.view.mas_width).multipliedBy(0.4);
        make.height.mas_equalTo(birthdayButton.mas_width);
        make.centerX.equalTo(self.view.mas_centerX).offset(- KSCREEN_WIDTH * 0.25);
        make.top.equalTo(self.marquee.mas_bottom).offset(42);
    }];
    [birthdayButton setBackgroundImage:[UIImage imageNamed:@"luck_entry_birthday_button_normal"] forState:UIControlStateNormal];
    [birthdayButton addTarget:self action:@selector(birthdayButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    //无敌上上签
    UIButton *drawButton = [[UIButton alloc] init];
    [self.view addSubview:drawButton];
    [drawButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(birthdayButton.mas_width);
        make.height.mas_equalTo(birthdayButton.mas_height);
        make.centerX.equalTo(self.view.mas_centerX).offset(KSCREEN_WIDTH * 0.25);
        make.top.equalTo(birthdayButton.mas_top);
    }];
    [drawButton setBackgroundImage:[UIImage imageNamed:@"luck_entry_lots_button_normal"] forState:UIControlStateNormal];
    [drawButton addTarget:self action:@selector(drawButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    //幸运数字选号仪
    UIButton *numberButton = [[UIButton alloc] init];
    [self.view addSubview:numberButton];
    [numberButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(birthdayButton);
        make.top.equalTo(birthdayButton.mas_bottom).offset(42);
        make.left.equalTo(birthdayButton.mas_left);
    }];
    [numberButton setBackgroundImage:[UIImage imageNamed:@"luck_entry_number_button_normal"] forState:UIControlStateNormal];
    [numberButton addTarget:self action:@selector(numberButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    //梦想大转盘
    UIButton *dreamButton = [[UIButton alloc] init];
    [self.view addSubview:dreamButton];
    [dreamButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(drawButton);
        make.top.equalTo(numberButton.mas_top);
        make.right.equalTo(drawButton.mas_right);
    }];
    [dreamButton setBackgroundImage:[UIImage imageNamed:@"luck_entry_roulette_button_normal"] forState:UIControlStateNormal];
    [dreamButton addTarget:self action:@selector(dreamButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
}

@end
